/**
 * 服务端接口调用
 */
import {
  GETRequest,
  GETAuthedRequest,
  POSTRequest,
  POSTAuthedRequest,
  PUTAuthedRequest,
  DELETEAuthedRequest,
  PUTRequest,
  DELETERequest,
} from 'utils/net-requests'

import {
  SYSTEM_FTP_CREATE,
  SYSTEM_FTP_GET_BY_ID,
  SYSTEM_FTP_PAGE_SEARCH_LIST,
  SYSTEM_FTP_REMOVE_BY_ID,
  SYSTEM_FTP_UPDATE_BY_ID,
  SYSTEM_FTP_UPDATE_STATUS_BY_ID,
  
  SYSTEM_WHIT_CREATE,
  SYSTEM_WHIT_GET_BY_ID,
  SYSTEM_WHIT_PAGE_SEARCH_LIST,
  SYSTEM_WHIT_REMOVE_BY_ID,
  SYSTEM_WHIT_UPDATE_BY_ID,
  SYSTEM_WHIT_UPDATE_STATUS_BY_ID,

  UCENTER_AUTH_USER_LOGIN,
  UCENTER_AUTH_GET_USER_AUTH_LIST,
  UCENTER_AUTH_GET_USER_INFO,
} from 'constants/server-apis';

/******************* ftp管理 开始 **********************/
/**
 * 根据id更新状态
 */
export const systemFtpUpdateStatusById = (jwt, id, status) => {
  return PUTAuthedRequest(jwt, SYSTEM_FTP_UPDATE_STATUS_BY_ID, { id, status });
}

/**
 * 根据id更新
 */
export const systemFtpUpdateById = (jwt, account, password, remark, url, id) => {
  const reqParamsJSON = {};

  // 如果某个参数为空或不存在，则不传给服务端
  !!remark && Object.assign(reqParamsJSON, { remark });
  Object.assign(reqParamsJSON, { account });
  Object.assign(reqParamsJSON, { password });
  Object.assign(reqParamsJSON, { url });
  Object.assign(reqParamsJSON, { id });
  return PUTAuthedRequest(jwt, SYSTEM_FTP_UPDATE_BY_ID, reqParamsJSON);
}

/**
 * 新增ftp
 */
export const systemFtpCreate = (jwt, account, password, remark, url, status) => {
  const reqParamsJSON = {};

  // 如果某个参数为空或不存在，则不传给服务端
  !!remark && Object.assign(reqParamsJSON, { remark });
  Object.assign(reqParamsJSON, { account });
  Object.assign(reqParamsJSON, { password });
  Object.assign(reqParamsJSON, { url });
  Object.assign(reqParamsJSON, { status });

  return POSTAuthedRequest(jwt, SYSTEM_FTP_CREATE, reqParamsJSON);
}

/**
 * 根据id获取
 */
export const systemFtpGetById = (jwt, id) => {
  return GETAuthedRequest(jwt, SYSTEM_FTP_GET_BY_ID, { id });
}

/**
 * 分页搜索列表
 */
export const systemFtpPageSearchList = (jwt, account, status, url, page, limit,) => {
  const reqParamsJSON = {};

  // 如果某个参数为空或不存在，则不传给服务端
  !!account && Object.assign(reqParamsJSON, { account });
  !!status && Object.assign(reqParamsJSON, { status });
  !!url && Object.assign(reqParamsJSON, { url });
  Object.assign(reqParamsJSON, { limit });
  Object.assign(reqParamsJSON, { page });

  return GETAuthedRequest(jwt, SYSTEM_FTP_PAGE_SEARCH_LIST, reqParamsJSON);
}

/**
 * 根据id删除
 */
export const systemFtpRemoveById = (jwt, id) => {
  return DELETEAuthedRequest(jwt, SYSTEM_FTP_REMOVE_BY_ID, { id });
}

/******************* ftp管理 结束 **********************/

/******************* 用户鉴权模块 开始 **********************/
/**
 * 用户登录
 */
export const ucenterAuthUserLogin = (ssost) => {
  return POSTRequest(UCENTER_AUTH_USER_LOGIN, { ssost });
}

/**
 * 获取用户信息
 */
export const ucenterAuthGetUserInfo = (jwt, userId) => {
  return GETAuthedRequest(jwt, UCENTER_AUTH_GET_USER_INFO, { userId });
}

/******************* 用户鉴权模块 结束 **********************/


/******************* 系统-白名单 开始 **********************/
/**
 * 创建
 */
export const systemWhitCreate = (jwt, name, keyID, keySecret, address, status, remarks) => {
  return POSTAuthedRequest(SYSTEM_WHIT_CREATE, { jwt, name, keyID, keySecret, address, status, remarks });
}

/**
 * 获取用户权限列表
 */
export const ucenterAuthGetUserAuthList = (jwt, userId) => {
  return GETAuthedRequest(jwt, UCENTER_AUTH_GET_USER_AUTH_LIST, { userId });
}

/******************* 系统-白名单 结束 **********************/